package Demo4;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-26
 * Time: 16:26
 */
public class Test {

    public static void main(String[] args) {
        Dog dog1 = new Dog("旺财",2);
        Dog dog2 = new Dog("旺财",2);

        System.out.println(dog1.equals(dog2));
        System.out.println(dog1.equals(dog1));
        System.out.println(dog1.hashCode());
        System.out.println(dog2.hashCode());

        System.out.println("--------------");

        Fish fish1 = new Fish("小鱼儿",3);
        Fish fish2 = new Fish("小鱼儿",3);

        System.out.println(fish1.equals(fish2));
        System.out.println(fish1.hashCode());
        System.out.println(fish2.hashCode());

        System.out.println("--------------");
        Duck duck1 = new Duck("唐老鸭",2);
        Duck duck2 = new Duck("唐老鸭",2);

        //没有修改对象中equals比较中的信息,值不同
        System.out.println(duck1.hashCode());
        System.out.println(dog2.hashCode());
    }

    public static void fuc(Animal animal) {
        animal.eat();
    }
    public static void running(IRun iRun) {
        iRun.run();
    }
    public static void swim(ISwimming iSwimming) {
        iSwimming.swimming();
    }
    public static void flying(IFly iFly) {
        iFly.fly();
    }

    public static void main3(String[] args) {
        swim(new Dog("旺财",1));
        swim(new Duck("唐老鸭",2));
        swim(new Fish("小鱼儿",3));

        System.out.println("----------");
        flying(new Duck("唐老鸭",2));
        System.out.println("----------");

        running(new Duck("唐老鸭",2));
        running(new Dog("旺财",1));
        System.out.println("----------");

        //非动物类也可以使用该接口
        Robot robot = new Robot();
        running(robot);
    }


    public static void main1(String[] args) {
        /*Animal animal1 = new Dog("旺财",1);
        Animal animal2 = new Duck("唐老鸭",2);
        Animal animal3 = new Fish("小鱼儿",3);*/
        fuc(new Dog("旺财",1));
        fuc(new Duck("唐老鸭",2));
        fuc(new Fish("小鱼儿",3));
    }
}
